/*
 * @Description:
 * @version:
 * @Author: 尹鹏孝
 * @Date: 2023-03-15 15:12:05
 * @LastEditors: 尹鹏孝
 * @LastEditTime: 2023-03-16 15:17:11
 */
'use static'

const bcrypt = require('bcrypt');
// const dayjs = require('dayjs');
const {
    Sequelize,
    DataTypes,
    Model
} = require('sequelize')
const {
    sequelize
} = require('../utils/db')

class User extends Model{

}
User.init({
    id:{
        type:DataTypes.INTEGER,
        primaryKey:true,
        // autoIncrement:true
    },
    username:{
        type: DataTypes.STRING,
        allowNull: false,
    },
    password:{
        type: DataTypes.STRING,
        allowNull: false,
             //观察者模式
            set(val) {
                 const salt = bcrypt.genSaltSync(10) // 10 计算机生成盐的成本  安全系数
                 const pwd = bcrypt.hashSync(val, salt) //密码加盐 防止彩虹攻击
                 this.setDataValue('password', pwd)
            }
    }
}, {
    sequelize,
    tableName: 't_sys_user',
    timestamps: false, //去除createAt updateAt
})

module.exports={
    User
}